﻿@model vngoodlife.Article

@{
    ViewBag.Title = "Article Edit";
    
}

<link href="../../../Content/themes/base/autocomplete.css" rel="stylesheet" type="text/css" />


<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript" src="@Url.Content("../../../Content/ckeditor/ckeditor.js")"></script>

<div class="twocolumn">
@using (Html.BeginForm("ArticleEdit", "Article", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
<div class="column_left" style="width:75%">
    <div class="header">
	    <span>Chỉnh sửa bài viết</span> 
        <div class="switchbutton">
                 <a href="@Url.Action("ArticleCreate", "Article")" class="button">&laquo;</a>
                 <a href="@Url.Action("ArticleCreate", "Article")" class="button">&raquo;</a>

                 <input type="submit" value="Lưu" style="margin: -10px 50px 0 0;"/>
                 <a href="@Url.Action("ArticleEdit", "Article", new { articleID = Model.ArticleID})"  class="button">Làm Lại</a>
            @if (Model.ArticleVisible)
                {
                <a href="@Url.RouteUrl("ArticleDetailFrontend", new { articleSeoUrl = Model.ArticleSeoUrl })" target="_blank" class="button">Xem nhanh</a>
                }
                <a href="@Url.Action("ArticleCreate", "Article")" class="button">Thêm mới</a>
                <a href="@Url.Action("ArticleList_BackEnd", "Article")" class="button">Danh sách</a>
        </div>
    </div>

    <br class="clear"/>
   
	<div class="content">
    
        <img src="../../../Content/images/article/thumbnail/@Model.Photo" alt="@Model.Photo" title="@Model.Title" class="img_h170"/>
        
        <div>
            <div  class="editor_left">
                <label>Mã số :</label>
                @Model.ArticleID
            </div>
            <div class="editor_middle">
                <label>Lượt xem :</label>
                @*@Model.ViewNumber*@
                @Html.TextBoxFor(u => u.ViewNumber, new { style = "width:60px;", maxlength = "6" })
            </div>
        </div>
        <br class="clear"/><br />

        <div>
            <div  class="editor_left">
                <label>Người viết :</label>
                @Model.MemberName
            </div>
            <div class="editor_middle">
                <label>Ngày tạo :</label>
                @String.Format(vngoodlife.Util.ConstantClass._dateTimeFormat, Model.CreateDate)
            </div>
        </div>
        <br class="clear"/><br />
       
       <div>
            <div  class="editor_left">
                <label>Quản lý :</label>
                @Model.AdminName
            </div>
            <div class="editor_middle">
                <label>Ngày sửa :</label>
                @String.Format(vngoodlife.Util.ConstantClass._dateTimeFormat, Model.UpdateDate)
            </div>
        </div>
        <br class="clear"/><br />
        
        @Html.AntiForgeryToken(vngoodlife.Util.AntiKey.EditSalt)
        @Html.HiddenFor(model => model.ArticleID)
         <div>
            <div  class="editor_left">
                <label>Trạng thái :</label><br />
                @Html.DropDownListFor(model => model.ArtStatusID, (SelectList)ViewBag.ArticleStatusList)
               @* @Html.DropDownList("ArtStatusID", (SelectList)ViewBag.ArticleStatusList, new { @style = "width:110px;" })*@
            </div>
            <div class="editor_middle">
                <label>Đăng ảnh(W:H = 1.6|0.75 & W>500|300):</label><br />
                <input name="uploadFile" id="File1" type="file" style="width: 250px;"/><br />
                @*@Html.HiddenFor(model => model.Photo)<br />*@
            </div>
        </div>
        <br class="clear"/><br />
        
        <div>
            <div  class="editor_left">
                <label>Highlight :</label>
                @Html.EditorFor(model => model.Focus)
                <label>Image :</label>
                @Html.EditorFor(model => model.IsImage)
                <br />
                <label>Hiện :</label>
                @Html.EditorFor(model => model.ArticleVisible)
                <label>Video :</label>
                @Html.EditorFor(model => model.IsVideo)
            </div>
            <div class="editor_middle">

            <label>Chủ đề(kỳ) :</label><br />
            @if (Model.ArtSubjectID != null)
            {
                @Html.TextBox("artSubjectName", Model.ArticleSubject.ArtSubjectName,
                                  new { style = "width:250px;", maxlength = "250",
                                        data_autocomplete = @Url.Action("GetSubject", "ArticleSubject"),
                                        targetid = "ArtSubjectID",
                                        multiple_line = "one"
                                  })
            }
            else
            {
                @Html.TextBox("artSubjectName", null, 
                              new { style = "width:250px;", maxlength = "250",
                                   data_autocomplete = @Url.Action("GetSubject", "ArticleSubject"),
                                   targetid = "ArtSubjectID",
                                   multiple_line = "one"
                              })
            }    
                @Html.HiddenFor(model => model.ArtSubjectID)
            </div>
            <div  class="editor_right"> <div class="errorMgs" style="margin: 25px 0 0 0;" >@Html.ValidationMessage("Notice")</div> </div>
        </div>
        <br class="clear"/><br />
           
        <div class="editor-label">
            <label class="label_ArticleEdit">Tiêu đề:</label> <div class="errorMgs" >@Html.ValidationMessageFor(model => model.Title)</div>
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Title, new {maxlength = "120" })
        </div>
        <br class="clear"/>
            
        <div class="editor-label">
            <label class="label_ArticleEdit">Mô tả :</label><div class="errorMgs" >@Html.ValidationMessageFor(model => model.Description)</div>
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Description)
        </div>
        <br class="clear"/>
            
        <div class="editor-label" style="margin: 0 0 20px 0;">
            <label class="label_ArticleEdit">Nội dung :</label><div class="errorMgs" >@Html.ValidationMessageFor(model => model.Content)</div>
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Content, new { @class = "ckeditor" })
        </div>
        <br class="clear"/><br />
        <script type="text/javascript">
            CKEDITOR.replace('Content', {
                BasePath: '../../../Content/ckeditor/',
                customConfig: 'CustomAdmin.js'
            });
	    </script>

        <p>
            <input type="submit" value="Lưu" style="margin: 10px 0 0 0;"/>
            <a href="@Url.Action("ArticleEdit", "Article", new { articleID = Model.ArticleID })"  class="buttonform">Làm Lại</a>
        </p>
    </div>
</div>@*end left column*@
        }


        @* Begin right column window *@
		<div class="column_right" style="width:24%">
            <div class="header">
				<span>Loại</span>
                <div class="switchbutton">
                    <div id="progress_Type">
                        <img src="../../../Content/images/general/loading.gif" alt="Loading"/>
                    </div>
                </div>
			</div>
			<br class="clear"/>
			<div class="content">
                 <div id="categoryDisplay">
                   @{Html.RenderAction("SetTypeIntoArticle", "Article", new { articleID = Model.ArticleID });}
                 </div>
                 @using (Ajax.BeginForm("SetTypeIntoArticle", "Article",
                                           new AjaxOptions
                                           {
                                               UpdateTargetId = "categoryDisplay",
                                               HttpMethod = "GET",
                                               InsertionMode = InsertionMode.Replace,
                                               LoadingElementId = "progress_Type",
                                               LoadingElementDuration = 2000,
                                               OnSuccess = "ClearValueType"
                                           }))
                 {
                    @*@Html.DropDownList("articleTypeID", (SelectList)ViewBag.ArticleTypeList," None ",
                                       new
                                           {
                                               textTargetID = "articleTypeNames",
                                               valueTargetID = "articleTypeIDs"
                                           })*@
                    Html.RenderAction("BuildArticleType_DropdownList", "Article",
                                    new {id="articleTypeID", textTargetID = "articleTypeNames", valueTargetID = "articleTypeIDs" });
                     
                     
                    @Html.Hidden("articleID", Model.ArticleID)
                    @Html.Hidden("articleTypeIDs", "0")
                    <input id="articleTypeSubjectButton" type="submit" value="Thêm" style="margin: 10px 0 0 0; padding: 3px 3px 3px 3px" />
                    <div id="articleTypeNames"  style="width: 240px; margin: 0 0 0 0px;padding: 10px 0 0 0px;">
                    </div>
                 }
                 
            </div>
        </div>
        <div style="float:right; width:200px; height:7px;"></div>
        <div class="column_right" style="width:24%">
            <div class="header">
				<span>Tags </span>
                <div class="switchbutton">
                    <div id="progress_tag">
                        <img src="../../../Content/images/general/loading.gif" alt="Loading"/>
                    </div>
                </div>
			</div>
			<br class="clear"/>
			<div class="content">
                <div id="tagDisplay">
                @{Html.RenderAction("SetTagsIntoArticle", "Article", new { artID = Model.ArticleID });}
                </div>
                @using (Ajax.BeginForm("SetTagsIntoArticle", "Article",
                                       new AjaxOptions
                                       {
                                           UpdateTargetId = "tagDisplay",
                                           HttpMethod = "GET",
                                           InsertionMode = InsertionMode.Replace,
                                           LoadingElementId = "progress_tag",
                                           LoadingElementDuration = 2000,
                                           OnSuccess = "ClearValueTag"
                                       }))
                {
                     
                @Html.TextBox("artTagName", null,
                              new
                              {
                                  style = "width:150px;",
                                  data_autocomplete = @Url.Action("GetTags2", "Tags", new { articleID = Model.ArticleID }),
                                  targetid = "tagID",
                                  multiple_line = "many"
                              })
                @Html.Hidden("tagID")
                @Html.Hidden("artID", Model.ArticleID)
                <input type="submit" value="Thêm" style="margin: 10px 0 0 0; padding: 3px 3px 3px 3px" />
                }
                <br />
                <label>Tạo tags</label>
                @using (Ajax.BeginForm("QuickCreateTag", "Tags",
                                       new AjaxOptions
                                       {
                                           UpdateTargetId = "tagMgs",
                                           HttpMethod = "GET",
                                           InsertionMode = InsertionMode.Replace,
                                           LoadingElementId = "progress_tag",
                                           LoadingElementDuration = 2000,
                                           OnSuccess = "ClearValueTag2"
                                       }))
                {
                @Html.TextBox("newTagName", null, new { style = "width:150px;" })
                <input type="submit" value="Tạo tag" style="margin: 10px 0 0 0; padding: 3px 3px 3px 3px" />
                }
                <div id="tagMgs" style="color:Red;"></div>
            </div>
        </div>
        
        <div style="float:right; width:200px; height:7px;"></div>
        <div class="column_right" style="width:24%">
            <div class="header">
				<span>Tạo nhanh chủ đề </span>
                <div class="switchbutton">
                    <div id="progress_sub">
                        <img src="../../../Content/images/general/loading.gif" alt="Loading"/>
                    </div>
                </div>
			</div>
			<br class="clear"/>
			<div class="content">
            @using (Ajax.BeginForm("QuickCreateSubject", "ArticleSubject",
                                       new AjaxOptions
                                       {
                                           UpdateTargetId = "subMgs",
                                           HttpMethod = "GET",
                                           InsertionMode = InsertionMode.Replace,
                                           LoadingElementId = "progress_sub",
                                           LoadingElementDuration=2000,
                                           OnBegin = "CheckValueSubject",
                                           OnSuccess = "ClearValueSubject"
                                       }))
            {
            @Html.TextBox("newSubjectName", null, new { style = "width:235px;" })
            <input type="submit" value="Tạo chủ đề" style="margin: 10px 0 0 0; padding: 3px 3px 3px 3px" />
            }
                <div id="subMgs" style="color:Red;"></div>
            </div>
        </div>
        
        <div style="float:right; width:200px; height:7px;"></div>
        <div class="column_right" style="width:24%">
            <div class="header">
				<span>Bài viết liên quan :</span>
                <div class="switchbutton">
                    <div id="progress_related">
                        <img src="../../../Content/images/general/loading.gif" alt="Loading"/>
                    </div>
                </div>
			</div>
			<br class="clear"/>
			<div class="content">
                <div id="relatedArticleDisplay">
                @{Html.RenderAction("SetRelatedArticle", "Article", new { articleID = Model.ArticleID });}
                </div>
                @using (Ajax.BeginForm("SetRelatedArticle", "Article",
                                       new AjaxOptions
                                       {
                                           UpdateTargetId = "relatedArticleDisplay",
                                           HttpMethod = "GET",
                                           InsertionMode = InsertionMode.Replace,
                                           LoadingElementId = "progress_related",
                                           LoadingElementDuration = 2000,
                                           OnSuccess = "ClearValueRelate",
                                           OnBegin = "CheckValueRelate"
                                       }))
                {
                @Html.TextBox("RelatedArticleName", null,
                              new
                              {
                                  style = "width:235px;",
                                  data_autocomplete = @Url.Action("GetArticleName", "Article", new { articleID = Model.ArticleID }),
                                  targetid = "relatedArticleID",
                                  multiple_line = "one"
                              })
                @Html.Hidden("relatedArticleID")
                @Html.Hidden("articleID", Model.ArticleID)
                <input type="submit" value="Thêm bài viết liên quan" style="margin: 10px 0 0 0; padding: 3px 3px 3px 3px" />
                }
                <div id="relateMgs" style="color:Red;"></div>
            </div>
        </div>
        @*end right column *@
</div>
<script type="text/javascript">
        function ClearValueType() {
            $("#articleTypeNames").empty();
            $("#articleTypeIDs").val("");
        }
        function ClearValueTag() {
            $("#artTagName").val("");
            $("#tagID").val("");
        }
        function ClearValueTag2() {
            $("#newTagName").val("");
        }
        function ClearValueRelate() {
            $("#RelatedArticleName").val("");
            $("#relatedArticleID").val("");
            $("#relateMgs").empty();
        }
        function ClearValueSubject() {
            $("#newSubjectName").val("");
        }


        function CheckValueRelate() {
            if ($("#RelatedArticleName").val() == "") {
                $("#relateMgs").html("Không được để trống");
            }
        }
        function CheckValueSubject() { 
            if ($("#newSubjectName").val() == "") {
                $("#subMgs").html("Không được để trống");
            }
        }
</script>